var express = require('express')
var router = require('./router')
var bodyParser = require('body-parser')
var app = express()
//配置body-parser之后req上会多出来一个属性body,post请求传进来的参数就在body中
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use('/public/',express.static('./public/'))


app.all('*',(req,res,next)=>{
    console.log('所有请求都必须经过这个方法')
    res.setHeader('Access-Control-Allow-Origin','*')
	res.setHeader('Access-Control-Allow-Methods', 'GET, POST')
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization')
    next()
})
//挂载
app.use(router)
app.listen(3000, ()=>{
    console.log('服务器已启动,请求地址为127.0.0.1:3000')
})